package cn.gson.springboot.info;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import cn.gson.springboot.model.pojos.User;

@Component
public class WebSecurityConfig implements HandlerInterceptor  {
	
	@Override
	 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception{
	    HttpSession session = request.getSession();
	    User user= (User) session.getAttribute("user");	   
		if(user!=null) {
			 return true;
		}else {
			String url="Land";
			response.sendRedirect(url);
			return false;
		}
		
	 }
	
	@Override
	 public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception{
		 
	 }
	
	@Override
	 public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)throws Exception{
		 
	 }
}
